function dressingByScreening(newObject, oldObject) {
  //newObject 为接收端 要被赋值的对象    oldObject 为发送过来的数据 赋值对象
  //作用  将oldObject赋值给newObject，如果其中的值为空则输出 ' - '；如果newObject为null则输出oldObject本身
  if (!oldObject) return newObject;
  Object.keys(newObject).forEach((item) => {
    newObject[item] = oldObject[item] ? oldObject[item] : "";
  });
  return newObject
}

//输入阿拉伯数字输出中国数字（仅支持0-99999）
function convertToChineseNumeral(num) {
  if (num == 10) {
    return '十'
  } else if (num == 1) {
    return '一'
  }
  const digits = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
  const units = ['', '十', '百', '千', '万'];
  let result = '';
  let numStr = num.toString();
  for (let i = 0; i < numStr.length; i++) {
    let digit = parseInt(numStr.charAt(i));
    let unit = units[numStr.length - i - 1];
    if (digit === 0) {
      // 当前数字为0时不需要输出汉字，但需要考虑上一个数字是否为0，避免出现连续的零
      if (result.charAt(result.length - 1) !== '零') {
        result += '零';
      }
    } else {
      result += digits[digit] + unit;
    }
  }
  // 对于一些特殊的数字，如10、100等，需要在最前面加上“一”
  if (result.charAt(0) === '一') {
    result = result.substr(1, result.length);
  } else if (result.charAt(0) === '百') {
    result = '一' + result;
  } else if (result.charAt(0) === '千') {
    result = '一' + result;
  }
  return result;
}


//将中国标准时间 转换为 年-月-日 时:分:秒
//type  1.转换为 年-月-日 时:分:秒
//      2.转换为 年-月-日
//      3.转换为 月-日
function convertDate(convTime,type=1){
  if(!convTime) return '1111-01-01 00:00:00'
  var date = new Date(convTime)
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  month = month < 10 ? '0' + month : month
  var da = date.getDate()
  da = da < 10 ? "0" + da : da
  var hours = date.getHours()
  hours = hours < 10 ? '0' + hours : hours
  var minutes = date.getMinutes()
  minutes = minutes < 10 ? '0' + minutes : minutes
  var secod = date.getSeconds()
  secod = secod < 10 ? '0' + secod : secod
  let str = ''
  switch(Number(type)){
    case 1:
      str = `${year}-${month}-${da} ${hours}:${minutes}:${secod}`
      break
    case 1:
      str = `${year}-${month}-${da}`
      break
    case 3:
      str = `${month}月${da}日`
      break
    default:
      break
  }
  return str
}

//获取年月日时分秒
function getDateFUnction(){
  var date = new Date()
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  month = month < 10 ? '0' + month : month
  var da = date.getDate()
  da = da < 10 ? "0" + da : da
  var hours = date.getHours()
  hours = hours < 10 ? '0' + hours : hours
  var minutes = date.getMinutes()
  minutes = minutes < 10 ? '0' + minutes : minutes
  var secod = date.getSeconds()
  secod = secod < 10 ? '0' + secod : secod
  return `${year}-${month}-${da} ${hours}:${minutes}:${secod}`
}

//输入风级，输出相应术语
function converScale(grade=0){
  grade = Number(grade)
  if(grade < 0 || grade > 12) return
  let str = ''
  switch(grade){
    case 0:
      str = `无风`
      break
    case 1:
      str = `软风`
      break
    case 2:
      str = `轻风`
      break
    case 3:
      str = `微风`
      break
    case 4:
      str = `和风`
      break
    case 5:
      str = `清风`
      break
    case 6:
      str = `强风`
      break
    case 7:
      str = `疾风`
      break
    case 8:
      str = `大风`
      break
    case 9:
      str = `烈风`
      break
    case 10:
      str = `狂风`
      break
    case 11:
      str = `暴风`
      break
    case 12:
      str = `飓风`
      break
    default:
      break
  }
  return str

}

//生成唯一id
function algorithm() {
  let abc = [
    "a",
    "b",
    "c",
    "d",
    "e",
    "f",
    "g",
    "h",
    "i",
    "g",
    "k",
    "l",
    "m",
    "n",
    "o",
    "p",
    "q",
    "r",
    "s",
    "t",
    "u",
    "v",
    "w",
    "x",
    "y",
    "z",
  ];
  let [max, min] = [
    Math.floor(Math.random() * (10 - 7 + 1) + 1),
    Math.floor(Math.random() * (17 - 10 + 1) + 17),
  ];
  abc = abc
    .sort(() => 0.4 - Math.random())
    .slice(max, min)
    .slice(0, 8)
    .join("");
  var a = new Date().getTime() + abc;
  return a;
}

// 输入框规则
function checkoutNumber(num,interLength=12,decLength=2){
  //默认保留12位整数，两位小数
  var str = num
  str = str + ''
  var length1 = str.substr(0,1)
  var length2 = str.substr(1,1)
  if(str.length > 1 && length1 == 0 && length2 != '.') str = str.substr(1,1)
  //第一位不能是点
  if(length1 == '.') str = '0.'
  //限制只能输入一个小数点
  str = str.replace(/^\.{2.}/g,'.')
  //保留数字和小数点
  str = str.replace(/[^\d^\.]+/g,'')
  //保留指定位数小数
  const reg = new RegExp('\\D*([0-9]\\d*\\.?\\d{0,' + decLength + '})?.*$')
  str = str.replace(reg,'$1')
  return zhengshuSclice(str,interLength,decLength)
}
function zhengshuSclice(data,interLength,decLength){
  let str = ''
  if(data.indexOf('.') == -1){
    str = data.length > interLength ? data.substr(0,interLength) : data
  }else{
    var integer = data.split('.')[0]
    var decimal = data.split('.')[1]
    if(integer.length > interLength) str = integer.substr(0,interLength) + '.' + decimal
    else str = integer + '.' + decimal
  }
  if(decLength == 0 && str.indexOf('.') != -1) str = str.slice(0,str.length - 1)
  return str
}



export {
  getDateFUnction,
  dressingByScreening,
  convertDate,
  converScale,
  convertToChineseNumeral,
  algorithm,
  checkoutNumber
}
